package com.android.pocketguru.Fragments;


import com.android.pocketguru.Constants;
import com.android.pocketguru.Phrases;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class DialogPopupFragment extends DialogFragment {

	private int phraseId = -1;
	
	//@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

        Bundle args= getArguments();
        if (args !=null)
        	phraseId = args.getInt(Constants.PHRASE_ID_KEY);
        
        if (phraseId==-1)
        	phraseId = Phrases.GetRandomPhraseId(getActivity().getBaseContext());
		
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

		builder.setTitle("Wisdom Alarm");
		builder.setMessage(Phrases.GetPhraseById(getActivity().getBaseContext(), phraseId));
		builder.setPositiveButton("OK", new OnClickListener() {
			//@Override
			public void onClick(DialogInterface dialog, int which) {
				/** Exit application on click OK */
				getActivity().finish();
			}						
		});
		
		/** Creating the alert dialog window */
		return builder.create();
	}
	
	/** The application should be exit, if the user presses the back button */ 
	//@Override
	public void onDestroy() {		
		super.onDestroy();
		getActivity().finish();
	}
}
